package com.yang.service;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.xml.ws.Endpoint;
import com.yang.LoginService;

public class ServiceManager {

	private static ServiceManager service = new ServiceManager();
	private InputStream is = null;
	private Properties pp = new Properties();

	private ServiceManager() {
		is = this.getClass().getClassLoader()
				.getResourceAsStream("net.properties");
		try {
			pp.load(is);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static ServiceManager newInstance() {
		return service;
	}

	private static Endpoint end = null;

	public boolean start() throws Exception {
		if (end == null || !end.isPublished()) {
			String url = pp.getProperty("url");
			end = Endpoint.publish(url, new LoginService());
			return end.isPublished();
		} else if (end.isPublished()) {
			return true;
		} else {
			return false;
		}
	}

	public boolean stop() throws Exception {
		if (end != null && end.isPublished()) {
			end.stop();
			return !end.isPublished();
		}
		return false;

	}

	public boolean reStart() throws Exception {
		stop();
		return start();
	}
}
